const { DataTypes } = require('sequelize');

module.exports = (sequelize) => {
  const Ad = sequelize.define('Ad', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  title: {
    type: DataTypes.STRING,
    allowNull: false
  },
  content: {
    type: DataTypes.TEXT,
    allowNull: false
  },
  imageUrl: {
    type: DataTypes.STRING,
    allowNull: true
  },
  videoUrl: {
    type: DataTypes.STRING,
    allowNull: true
  },
  duration: {
    type: DataTypes.INTEGER,
    defaultValue: 30,
    comment: '广告时长(秒)'
  },
  pointsReward: {
    type: DataTypes.INTEGER,
    defaultValue: 1,
    comment: '观看奖励积分'
  },
  position: {
    type: DataTypes.ENUM('banner', 'popup', 'video', 'native'),
    defaultValue: 'banner'
  },
  status: {
    type: DataTypes.ENUM('active', 'inactive', 'expired'),
    defaultValue: 'active'
  },
  priority: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
    comment: '优先级，数字越大优先级越高'
  },
  startTime: {
    type: DataTypes.DATE,
    allowNull: true
  },
  endTime: {
    type: DataTypes.DATE,
    allowNull: true
  },
  targetAudience: {
    type: DataTypes.JSON,
    allowNull: true,
    comment: '目标受众配置'
  },
  clickUrl: {
    type: DataTypes.STRING,
    allowNull: true,
    comment: '点击跳转链接'
  },
  viewCount: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
    comment: '观看次数'
  },
  clickCount: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
    comment: '点击次数'
  },
  budget: {
    type: DataTypes.DECIMAL(10, 2),
    allowNull: true,
    comment: '广告预算'
  },
  spent: {
    type: DataTypes.DECIMAL(10, 2),
    defaultValue: 0,
    comment: '已花费金额'
  }
}, {
  tableName: 'ads',
  timestamps: true
});

  return Ad;
};